import { createApp } from 'vue';
import App from './App.vue';
/**element*/
import 'element-plus/dist/index.css';
import ElementPlus from 'element-plus';
/**element icons组件*/
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import 'element-plus/theme-chalk/dark/css-vars.css';
/**导入Pinia*/
import store from './store';
/**全局样式*/
import './style/style.css';
import './style/theme.css';
/**routes*/
import router from './router';
/*svg图标注册*/
import 'virtual:svg-icons-register';
// body 上额外扩展的属性名
const THEME_MODE_ATTR = 'theme-mode';
function setRem() {
  const baseSize = 14; // 对应设计稿 1920px / 120 = 16
  const scale = document.documentElement.clientWidth / 1080;
  document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px';
}

window.addEventListener('resize', setRem);
setRem();
/**
 * 切换主题
 * @param themeTag 主题标识
 */
export const changeTheme = (themeTag) => {
  const lowerThemeTag = themeTag.toLocaleLowerCase();
  document.body.setAttribute(THEME_MODE_ATTR, lowerThemeTag);
};

/**buffer导入以及*/
import * as buffer from 'buffer';
//global is not defined和Buffer is not defined的解决方法
if (typeof window.global === 'undefined') {
  window.global = window;
}
if (typeof window.Buffer === 'undefined') {
  window.Buffer = buffer.Buffer;
}

const app = createApp(App);

/**注册element-icon*/
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
app.use(ElementPlus);
app.use(store);
app.use(router);
app.mount('#app');
